<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8">
<title>后台管理界面</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../style/bootstrap.css" />
<link rel="stylesheet" href="style/login.css" />
</head>

<body>
	<div class="container">
		<header>
			<h1>睿迅电商管理系统</h1>
			<div>
				<span class="glyphicon glyphicon-home"></span>
			</div>

		</header>
		<div class="row">
			<div
				class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 col-xs-offset-1 col-xs-10 login">
				<!--头像-->
				<div class="login-head">
					<img src="images/head_120.png" alt="" class="img-circle">
				</div>
				<!--表单-->
				<!-- <form class="login-form" action="/admin/AdminServlet?flag=login"
					method="post"> -->
				<div class="login-form">
					<div class="input-group">
						<span class="input-group-addon glyphicon glyphicon-user"></span> <input
							id="username" type="text" name="username" class="form-control" value="admin"
							placeholder="用户名" required autofocus />
					</div>
					<div class="input-group">
						<span class="input-group-addon glyphicon glyphicon-lock"></span> <input
							id="password" type="password" name="password"  value="123456"
							class="form-control" placeholder="密码" required />
					</div>
					<button id="btnLogin" class="btn btn-lg btn-warning btn-block"
						type="submit">登录</button>
					<div class="checkbox">
						<label> <input type="checkbox">记住密码
						</label>
					</div>
				</div>
				<!-- </form> -->
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
		var xmlhttp;
		if (window.XMLHttpRequest)
		{
		  xmlhttp=new XMLHttpRequest();
		}
		/**
		*登录
		*/
	    document.getElementById("btnLogin").onclick=function(){
		var username=document.getElementById("username").value;
		var password=document.getElementById("password").value;
		var parentNode=document.querySelector(".login-form"); 
		if(username==""){
			showinfo(parentNode,"账号不能为空！")
			return;
		}
		if(password==""){
			showinfo(parentNode,"密码不能为空！");
			return;
		}
		xmlhttp.open("POST","/admin/AdminServlet?flag=login",true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("username="+username+"&password="+password);
		xmlhttp.onreadystatechange=function()
		 {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		   {
			    if(xmlhttp.responseText=="success"){
			    	window.location.href="/admin/index.jsp";
				}else if(xmlhttp.responseText=="fail"){
					//消息提示
					showinfo(parentNode,"用户名密码不正确，请重新输入！")
					
				}
		    }
		 }
	}
	/**
	*显示错误消息
	*/
	function showinfo(parentNode,info){
		//alert(parentNode.childNodes[1].nodeName==SPAN)
	 	if(parentNode.childNodes[1].nodeName=="SPAN"){
			parentNode.removeChild(parentNode.childNodes[1]); 
		}
		//创建节点
		var node=document.createElement("span");
		var textnode=document.createTextNode(info);
		//添加子节点到父节点
		node.appendChild(textnode);
		node.setAttribute("style","color:red");
		//向第一个元素前插入新节点
		parentNode.insertBefore(node,parentNode.childNodes[1]);
	}
	
</script>
</html>